﻿$(function() {
    JSUtility.param.Options["InternalType"] = "0";
    JSUtility.param.ClassName = "OA.Bll.Project.ProjectIncomePresenter";

    autoResize({ dataGrid: '#Grid', callback: Initlist });

    JSUtility.window_edit = $('#Add').window({
        iconCls: 'icon-add',
        zIndex: 1000,
        draggable: true,
        resizable: false,
        shadow: true,
        inline: true,
        modal: true,
        title: '添加项目回款现金信息',
        collapsible: false,
        minimizable: false,
        maximizable: false,
        closable: true,
        width: 450,
        // height: 240,
        closed: true,
        onOpen: function() {
            $('#Add').parent().css("left", "25%");
            $('#Add').parent().next().css("left", "25%");
            $('#Add').parent().next().css("top", "25%");
            $('#Add').parent().css("top", "25%");
        }
    });
    $('#Add').show();
    JSUtility.window_edit_title = "项目回款现金信息";
    JSUtility.window_edit_form = $("#Add").find("form");
});

function refresh() {
    var contractsId = null; // self.parent.payBackId;
    if (self.parent.payBackId != "") {
        contractsId = self.parent.payBackId;  //self.parent.parent.public_ids.options["ProjectPayBackId"];
        JSUtility.param.Options["PaybackId"] = contractsId;
        JSUtility.replenish = function() {
            $("#PaybackId").val(contractsId);
        };
        $("#PaybackId").attr("readonly", "readonly");
    }
    JSUtility.grid.datagrid({ method: "post", queryParams: { "json": $.toJSON(JSUtility.param) }, url: JSUtility.url });
}

function Initlist(size) {
    var contractsId = null; // self.parent.payBackId;
    if (self.parent.payBackId != "") {
        contractsId = self.parent.payBackId;  //self.parent.parent.public_ids.options["ProjectPayBackId"];
        JSUtility.param.Options["PaybackId"] = contractsId;
        JSUtility.replenish = function() {
            $("#PaybackId").val(contractsId);
        };
        $("#PaybackId").attr("readonly", "readonly");
    }
    //    else {
    //        contractsId = self.parent.public_ids.options["ProjectPayBackId"];
    //    }
    JSUtility.param.Method = "Search";
    JSUtility.grid = $('#Grid').datagrid({
        tilte: '项目回款现金信息',
        iconCls: 'icon-save',
        width: size.width,
        height: size.height,
        pageSize: Math.round(size.height / 25),
        pageList: [Math.round(size.height / 25)],
        nowrap: true,
        striped: true,
        url: JSUtility.url,
        queryParams: { "json": $.toJSON(JSUtility.param) },
        sortName: 'Id',
        sortOrder: 'desc',
        idField: 'Id',
        frozenColumns: [[{ title: '编号', field: 'Id', width: 50, sortable: true}]],
        columns: [[
                            { title: '回款申请编号', field: 'PaybackId', width: 80 },
                            { title: '单位名称', field: 'Company', width: 80 },
                            { title: '开票时间', field: 'BillTime', width: 80 },
                            { title: '开票金额', field: 'Income', width: 80 },                            
                           // { title: '到账金额', field: 'BillAmount', width: 80 },
                            { title: '累计收入', field: 'TotalIncome', width: 80 }

                        ]],
        pagination: true,
        rownumbers: true,
        singleSelect: true,
        onDblClickRow: function() {
        EditProjectCash();
        },
        toolbar: [
                    {
                        text: '添加',
                        iconCls: 'icon-add',
                        handler: JSUtility.add
                    }, '-',
                    {
                        text: '修改',
                        iconCls: 'icon-edit',
                        handler: JSUtility.update
                    }, '-',
                    {
                        text: '删除',
                        iconCls: 'icon-remove',
                        handler: JSUtility.del
                    }, '-',
                    {
                        text: '查询',
                        iconCls: 'icon-search',
                        handler: JSUtility.search
                    }, '-',
                    {
                        text: '现金收入',
                        iconCls: 'icon-edit',
                        handler: EditProjectCash
                    }
                  ]
        //        onSelect: function(index, rowData) {
        //            self.parent.incomeId = rowData.Id;
        //            self.parent.InitIncome();
        //        }
    });
}
function Add() {
    $('#Add').window({ title: '添加项目回款现金信息', iconCls: 'icon-add', closed: false });
}
function Update() {
    $('#Add').window({ title: '修改项目回款现金信息', iconCls: 'icon-edit', closed: false });
}
function Search() {
    $('#Add').window({ title: '查询项目回款现金信息', iconCls: 'icon-search', closed: false });
}
//项目现金
function EditProjectCash() {
    var row = JSHelper.isDatagridSelected($("#Grid"));
    if (row == null) return;
    //if (self.parent.IncomeId != "") {
    self.parent.projectInfoManager.addTab("项目回款现金", "Project/ProjectCashInfo.htm", "icon-edit");
    self.parent.IncomeId = row.Id;
    // }
    //    if (!self.parent.projectInfoManager) {
    //        self.parent.addTab("项目收入现金", "Project/ProjectCashInfo.htm", "icon-edit");
    //        self.parent.public_ids.options["ProjectIncomeId"] = row.Id;
    //    } else {
    //        self.parent.projectInfoManager.addTab("项目收入现金", "ProjectCashInfo.htm", "icon-edit");
    //        self.parent.parent.public_ids.options["ProjectIncomeId"] = row.Id;
    //    }
    //    data = JSHelper.isDatagridSelected();
    //    if (data != null) {
    //        JSHelper.addTab('合同委外', 'Project/ContractsOutsourcingInfo.htm', 'icon-add');
    //    }
}